package com.yogee.topseller.fragment.zhoubian;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.core.utils.ToastUtils;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.XzcfActivity;
import com.yogee.topseller.activity.ZhoubianActivity;
import com.yogee.topseller.activity.tianyan.BzxrDetailActivity;
import com.yogee.topseller.activity.tianyan.GphqDetailActivity;
import com.yogee.topseller.activity.tianyan.QyfxActivity;
import com.yogee.topseller.bean.BzxrBean;
import com.yogee.topseller.bean.DcdyBean;
import com.yogee.topseller.bean.GbbdBean;
import com.yogee.topseller.bean.GbjgBean;
import com.yogee.topseller.bean.GpfhBean;
import com.yogee.topseller.bean.GphqBean;
import com.yogee.topseller.bean.GqczBean;
import com.yogee.topseller.bean.GrfxBean;
import com.yogee.topseller.bean.JigouBean;
import com.yogee.topseller.bean.JyycBean;
import com.yogee.topseller.bean.QyfxBean;
import com.yogee.topseller.bean.SxrBean;
import com.yogee.topseller.bean.XzcfBean;
import com.yogee.topseller.bean.YzwfBean;
import com.yogee.topseller.bean.ZqxxBean;
import com.yogee.topseller.fragment.productdetail.BaseFragment;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.utils.AppUtil;
import com.yogee.topseller.utils.Constants;
import com.yogee.topseller.utils.LogUtils;

import java.io.Serializable;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 风险
 * Created by zwj on 2017/12/7.
 */

public class FengxianFragment2 extends BaseFragment implements ZhoubianActivity.UpdateListener{
    @BindView(R.id.ll_item1)
    LinearLayout ll_item1;
    @BindView(R.id.ll_item2)
    LinearLayout ll_item2;
    @BindView(R.id.ll_item3)
    LinearLayout ll_item3;
    @BindView(R.id.ll_item4)
    LinearLayout ll_item4;
    @BindView(R.id.ll_item5)
    LinearLayout ll_item5;
    @BindView(R.id.ll_item6)
    LinearLayout ll_item6;
    @BindView(R.id.ll_item7)
    LinearLayout ll_item7;
    @BindView(R.id.ll_item8)
    LinearLayout ll_item8;
    @BindView(R.id.ll_item9)
    LinearLayout ll_item9;
    @BindView(R.id.ll_item10)
    LinearLayout ll_item10;
    @BindView(R.id.ll_item11)
    LinearLayout ll_item11;
    @BindView(R.id.ll_item12)
    LinearLayout ll_item12;
    @BindView(R.id.ll_item13)
    LinearLayout ll_item13;
    @BindView(R.id.ll_item14)
    LinearLayout ll_item14;
    @BindView(R.id.ll_item15)
    LinearLayout ll_item15;

    Unbinder unbinder1;
    private int isMj = 0;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_fengxian1;
    }


    @Override
    protected void initView() {
        ((ZhoubianActivity)getActivity()).setListener1(this);



    }

    @OnClick({R.id.ll_item1,R.id.ll_item2,R.id.ll_item3,R.id.ll_item4,R.id.ll_item5,R.id.ll_item6,R.id.ll_item7,R.id.ll_item8,R.id.ll_item9,R.id.ll_item10,R.id.ll_item11,R.id.ll_item12,R.id.ll_item13,R.id.ll_item14,R.id.ll_item15})
    public void onViewClicked(View view) {
        switch (view.getId()){
            // 行政处罚
            case R.id.ll_item1:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckXZCF(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_XZRF_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<XzcfBean>() {
                    @Override
                    public void onNext(XzcfBean o) {
                        if(o.getEyeCheck().getError_code()==0){
                            startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                    .putExtra("title","行政处罚")
                                    .putExtra("type",Constants.EyeCheck_XZRF_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItems()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }
                    }
                }, this));

                break;
            // 严重违法
            case R.id.ll_item2:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckYzwf(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_YZWF_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<YzwfBean>() {
                    @Override
                    public void onNext(YzwfBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            yzwfAdapter.addData(o.getEyeCheck().getResult().getItems());
                            startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                    .putExtra("title","严重违法")
                                    .putExtra("type",Constants.EyeCheck_YZWF_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItems()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));

                break;
            // 股权出质
            case R.id.ll_item3:
//                ToastUtils.showToast(getActivity(),"暂无数据");

                HttpManager.getInstance().eyeCheckGqcz(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_GQCZ_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GqczBean>() {
                    @Override
                    public void onNext(GqczBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            gqczAdapter.addData(o.getEyeCheck().getResult().getItems());
                            startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                    .putExtra("title","股权出质")
                                    .putExtra("type",Constants.EyeCheck_GQCZ_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItems()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }
                    }
                }, this));

                break;
            // 股本变动
            case R.id.ll_item4:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckGBBD(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_GBBD_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GbbdBean>() {
                    @Override
                    public void onNext(GbbdBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            gbbdAdapter.addData(o.getEyeCheck().getResult().getItems());
                            startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                    .putExtra("title","股本变动")
                                    .putExtra("type",Constants.EyeCheck_GBBD_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItems()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));

                break;
            // 企业风险
            case R.id.ll_item5:
//                ToastUtils.showToast(getActivity(),"暂无数据");
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckQyfx(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_QYFX_TYPE, AppUtil.getUserId(getActivity()),((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<QyfxBean>() {
                    @Override
                    public void onNext(QyfxBean o) {
                        if(o.getEyeCheck().getError_code()==0){

                            startActivity(new Intent().setClass(getActivity(), QyfxActivity.class)
                                    .putExtra("title","企业风险")
                                    .putExtra("type",Constants.EyeCheck_QYFX_TYPE)
                                    .putExtra("info", (Serializable) o));

                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));



                break;
            // 经营异常
            case R.id.ll_item6:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckJyyc(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_JYYC_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<JyycBean>() {
                    @Override
                    public void onNext(JyycBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            jyycAdapter.addData(o.getEyeCheck().getResult().getItems());
                            startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                    .putExtra("title","经营异常")
                                    .putExtra("type",Constants.EyeCheck_JYYC_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItems()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));
                break;
            // 动产抵押
            case R.id.ll_item7:
//                ToastUtils.showToast(getActivity(),"暂无数据");
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckDcdy(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_DCDY_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<DcdyBean>() {
                    @Override
                    public void onNext(DcdyBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            dcdyAdapter.addData(o.getEyeCheck().getResult().getItem());
                            startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                    .putExtra("title","动产抵押")
                                    .putExtra("type",Constants.EyeCheck_DCDY_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItem()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }
                    }
                }, this));
                break;
            // 失信人
            case R.id.ll_item8:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckSXR(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_SXR_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<SxrBean>() {
                    @Override
                    public void onNext(SxrBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            sxrAdapter.addData(o.getEyeCheck().getResult().getItems());
                            startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                    .putExtra("title","失信人")
                                    .putExtra("type",Constants.EyeCheck_SXR_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItems()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));

                break;
            // 被执行人
            case R.id.ll_item9:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckBzxr(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_BZXR_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<BzxrBean>() {
                    @Override
                    public void onNext(BzxrBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            detailAdapter.addData(o.getEyeCheck().getResult().getItems());
                            startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                    .putExtra("title","被执行人")
                                    .putExtra("type",Constants.EyeCheck_BZXR_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItems()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));

                break;
            // 人风险
            case R.id.ll_item10:
                if(pd!=null)
                    pd.show();
//                ToastUtils.showToast(getActivity(),"暂无数据");
                HttpManager.getInstance().eyeCheckGrfx(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_RFX_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GrfxBean>() {
                    @Override
                    public void onNext(GrfxBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            grfxAdapter.addData(o.getEyeCheck().getResult().getExternalList());
                            startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                    .putExtra("title","个人风险")
                                    .putExtra("type",Constants.EyeCheck_RFX_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getExternalList()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));

                break;
            // 股本机构
            case R.id.ll_item11:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckGBJG(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_GBJG_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GbjgBean>() {
                    @Override
                    public void onNext(GbjgBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            gbjgAdapter.addData(o.getEyeCheck().getResult().getDataList());
                            startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                    .putExtra("title","股本结构")
                                    .putExtra("type",Constants.EyeCheck_GBJG_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getDataList()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));

                break;
            // 股票行情
            case R.id.ll_item12:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckGPHQ(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_GBJG_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GphqBean>() {
                    @Override
                    public void onNext(GphqBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                    detailAdapter.addData(o.getEyeCheck().getResult().getItems());
//                            setData(o.getEyeCheck().getResult());
                            startActivity(new Intent().setClass(getActivity(), GphqDetailActivity.class)
                                    .putExtra("title","股票行情")
                                    .putExtra("type",Constants.EyeCheck_GBJG_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));

                break;
            // 股票简介
            case R.id.ll_item13:
                ToastUtils.showToast(getActivity(),"暂无数据");
                break;
            // 股票分红
            case R.id.ll_item14:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckGPFH(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_GPFH_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GpfhBean>() {
                    @Override
                    public void onNext(GpfhBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            gpfhAdapter.addData(o.getEyeCheck().getResult().getItems());
                            startActivity(new Intent().setClass(getActivity(), BzxrDetailActivity.class)
                                    .putExtra("title","股票分红")
                                    .putExtra("type",Constants.EyeCheck_GPFH_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItems()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }

                    }
                }, this));

                break;
            // 债券信息
            case R.id.ll_item15:
                if(pd!=null)
                    pd.show();
                HttpManager.getInstance().eyeCheckZqxx(((ZhoubianActivity)getActivity()).getMySelectCompany().getId(),
                        Constants.EyeCheck_ZJXX_TYPE, AppUtil.getUserId(getActivity()),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getType(),
                        ((ZhoubianActivity)getActivity()).getMySelectCompany().getProId()).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<ZqxxBean>() {
                    @Override
                    public void onNext(ZqxxBean o) {
                        if(o.getEyeCheck().getError_code()==0){
//                            zqxxListAdapter.addData(o.getEyeCheck().getResult().getItems());
                            startActivity(new Intent().setClass(getActivity(), XzcfActivity.class)
                                    .putExtra("title","债券信息")
                                    .putExtra("type",Constants.EyeCheck_ZJXX_TYPE)
                                    .putExtra("info", (Serializable) o.getEyeCheck().getResult().getItems()));
                        }else{
                            ToastUtils.showToast(getActivity(),"无数据");
                        }
                    }
                }, this));

                break;
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder1 = ButterKnife.bind(this, rootView);

        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder1.unbind();
    }

    @Override
    public String getTitle() {
        return "机构相关";
    }


    @Override
    public void getCurrentPos(JigouBean.Company company) {
        LogUtils.e("sfz","风险:"+company.getName());
        LogUtils.e("sfz","风险type:"+company.getType());
    }
}
